package com.base.web.socket.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.base.common.sys.service.SysUserService;

@Controller
@RequestMapping("/")
public class SocketController {

	@Resource
	private SysUserService sysUserService;
	
	@GetMapping({"/socket", "/"})
	public String toChatHome(Integer userId, Model model) {
		return "chat-home";
	}
	
	
	
	
	// 推送数据接口
	/*@ResponseBody
	@RequestMapping("/socket/push/{cid}")
	public R pushToWeb(@PathVariable String cid, String message) {
		try {
			WebSocketServer.onMessage(message, cid);
		} catch (IOException e) {
			e.printStackTrace();
			return R.error(cid + "#" + e.getMessage());
		}
		return R.ok(cid);
	}*/
	
	/************* 测试 *************/
	
	// 页面请求
	@GetMapping("/sys/socket")
	public String socket(Model model) {
		return "socket";
	}
	
	@GetMapping("/socket-chat-1")
	public String toSocketChat(Model model) {
		model.addAttribute("userId", "100");
		model.addAttribute("toUserId", "200");
		return "socket-chat";
	}
	
	@GetMapping("/socket-chat-2")
	public String toSocketChat2(Model model) {
		model.addAttribute("userId", "200");
		model.addAttribute("toUserId", "100");
		return "socket-chat";
	}
}
